package com.example.MatchGame;


import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;

import com.example.wonderfulradish.PagerViewAdapter;
import com.example.wonderfulradish.R;

import java.util.ArrayList;
import java.util.List;

public class StartMatchActivity extends AppCompatActivity implements View.OnClickListener{
    private ViewPager matchViewPager;
    private ArrayList<View> matchpageview;
    private Button greenmatchstart, orangematchstart,purplematchstart;
    private Button greenmatchback,orangematchback,purplematchback;
    public final int GREEN=1;
    public final int ORANGE=2;
    public final int PURPLE=3;
    private int flag;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start_match);
        //加载viewPager
        matchViewPager=(ViewPager) findViewById(R.id.match_view_pager);

        LayoutInflater inflater=getLayoutInflater();
        View matchgreen=inflater.inflate(R.layout.match_green,null);
        View matchpurple=inflater.inflate(R.layout.match_purple,null);
        View matchorange=inflater.inflate(R.layout.match_orange,null);


        matchpageview=new ArrayList<View>();
        //添加想要切换的界面
        matchpageview.add(matchgreen);
        matchpageview.add(matchorange);
        matchpageview.add(matchpurple);

        //数据适配器
        PagerViewAdapter newPagerAdapter=new PagerViewAdapter(matchpageview);
        //绑定适配器
        matchViewPager.setAdapter(newPagerAdapter);

        //获取子view的控件开始按钮
        orangematchstart=(Button) matchorange.findViewById(R.id.orangematchstart);
        orangematchstart.setOnClickListener(this);
        greenmatchstart=(Button) matchgreen.findViewById(R.id.greenmatchstart);
        greenmatchstart.setOnClickListener(this);
        purplematchstart=(Button) matchpurple.findViewById(R.id.purplestart);
        purplematchstart.setOnClickListener(this);

        //返回按钮
//        orangematchback=(Button) matchorange.findViewById(R.id.matchorangeback);
//        orangematchback.setOnClickListener(this);
        greenmatchback=(Button) matchgreen.findViewById(R.id.greenmanchback);
        greenmatchback.setOnClickListener(this);
//        purplematchback=(Button) matchgreen.findViewById(R.id.matchpurpleback);
//        purplematchback.setOnClickListener(this);

    }

    @Override
    public void onClick(View v){
        switch (v.getId()) {
            case R.id.orangematchstart:
                flag=ORANGE;
                Intent intent=new Intent(StartMatchActivity.this,MatchDrawView.class);
                startActivity(intent);
                //实现一个类，传入flag的值，判断游戏应该加载的页面
                break;
            case R.id.greenmatchstart:
                flag=GREEN;
                Intent intent1=new Intent(StartMatchActivity.this,MatchGame.class);
                startActivity(intent1);
                break;
            case R.id.purplestart:
                flag=PURPLE;
                Intent intent2=new Intent(StartMatchActivity.this,MatchGame.class);
                startActivity(intent2);
                break;
            case R.id.matchorangeback:
                Intent intent3=new Intent(StartMatchActivity.this,MatchSelecte.class);
                startActivity(intent3);
                break;
            case R.id.matchpurpleback:
                Intent intent4=new Intent(StartMatchActivity.this,MatchSelecte.class);
                startActivity(intent4);
                break;
            case R.id.greenmanchback:
                Intent intent5=new Intent(StartMatchActivity.this,MatchSelecte.class);
                startActivity(intent5);
                break;
            default:
                break;
        }
    }
}
